<?php
/**
 * @copyright : ienter asia Technologies
 * @author :  HungLV
 * @version    Release: V1.0
 * @Description : Class conversion rate   
 */
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Mod_conversion extends MYAD_Controller{
/*
 * @author :        HungLV
 * @created:        
 * @Description:  Load library Model conversion
 * @Input :         Null
 * @Output :        Null
 */        
    protected $table_name = 'm_currencyconversionrate';
    public function __construct(){
        parent::__construct();
        $this->load->model('Mmod_conversion');
    }
/*
 * @author :        HungLV
 * @created:        
 * @Description:    Get all conversion data
 * @Input :         $page = 0
 * @Output :        Return array conversion for data view
 */ 
    public function index($page = 0){
        $this->load->library('pagination');
        $data = $this->Mmod_conversion->getAllConversionRate($page);
        $this->load->view('layout',$data);
    }
/*
 * @author :        HungLV
 * @created:        
 * @Description:    Insert conversion Rate
 * @Input :         Null
 * @Output :        
 */  
    function addConversion(){
        $temp = array();
        $info = array();
        if($this->input->post('btnSubmit')){
            $validate = $this->Mmod_conversion->validate();
            if($validate){
                if($this->Mmod_conversion->checkDuplicateConversion($this->input->post('txtApplyDate'))){
                    // insert data to database
                    $result = $this->Mmod_conversion->insertDataConversion();
                    if($result == TRUE){
                        $temp['flag'] = TRUE;
                        $temp['message'] = $this->lang->line('CR_updateDB_success');                       
                    }
                    else{
                        $temp['flag'] = FALSE;
                        $temp['message'] = $this->lang->line('CR_updateDB_fall');					
                    }                    
                }
                else{
                        $temp['flag'] = FALSE;
                        $temp['message'] = $this->lang->line('OVT_updateDB_duplicate');                    
                }
            }
	   }
        $info = $this->Mmod_conversion->getInfoData($this->lang->line('CR_conversion_registration'),'add_conversion');
        $data = array_merge($temp,$info);
        $this->load->view('layout',$data);            
    }
/*
 * @author :        HungLV
 * @created:        
 * @Description:    Edit conversion Rate by Id
 * @Input :         $id conversion rate
 * @Output :        Null
 */      
    function editConversion(){
        $temp = array();
        $info = array(); 
        $id = $this->input->post('id');
        if($this->Mmod_conversion->checkExist($id)){
            $temp['RateId'] = $id;
            if($this->input->post('btnSubmit')){
                if($this->Mmod_conversion->checkExist($id)){
                    $validate = $this->Mmod_conversion->validate();
                    if($validate){
                       if($this->Mmod_conversion->checkDuplicateConversion($this->input->post('txtApplyDate'),$id)){
                            $result = $this->Mmod_conversion->updateDataConversion($id);
                            if($result == TRUE){
                                 $temp['flag'] = TRUE;		
                                 $temp['message'] = $this->lang->line('CR_updateDB_success');                       
                            }
                            else{
                                 $temp['flag'] = FALSE;
                                 $temp['message'] = $this->lang->line('CR_updateDB_fall');                         
                            }
                        }
                        else{
                            $temp['flag'] = FALSE;
                            $temp['message'] = $this->lang->line('OVT_updateDB_duplicate');                              
                        }
                   }
                }
                else{
                    redirect('/conversion');
                }
                $temp['chkDelFlag'] = $this->input->post('chkDelFlag'); 
            }
            else{
                $condition = array(
                    'where'=>array(
                        'RateId'=>$id,
                        'CompanyCode'=>$this->session->userdata('CompanyCode'),
                    ),
                    'first' => true,
                );
                $temp['data'] = $this->Mmod_conversion->selectDB($this->table_name,$condition);
                $temp['chkDelFlag'] = $temp['data']->Del_Flag;
            }
            $temp['id'] = $id;      
            $info = $this->Mmod_conversion->getInfoData($this->lang->line('CR_conversion_edit'),'edit_conversion');
            $data = array_merge($temp,$info);
            $this->load->view('layout',$data);
        }
        else{
            redirect('/conversion');
        }    
    }
}
?>